package com.atguigu.gmall.mq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

/**
 * 延时队列配置类
 *
 * @author Fxz
 * @version 1.0
 * @date 2022-02-20 22:49
 */
@Configuration
public class DelayedMqConfig {

	public static final String exchange_delay = "exchange.delay";

	public static final String routing_delay = "routing.delay";

	public static final String queue_delay_1 = "queue.delay.1";

	@Bean
	public Queue delayQueue() {
		return QueueBuilder.durable(queue_delay_1).build();
	}

	@Bean
	public CustomExchange delayExchange() {
		HashMap<String, Object> map = new HashMap<>();
		map.put("x-delayed-type", "direct");
		return new CustomExchange(exchange_delay, "x-delayed-message", true, false, map);
	}

	@Bean
	public Binding delayBinding() {
		return BindingBuilder.bind(delayQueue()).to(delayExchange()).with(routing_delay).noargs();
	}

}
